#pragma once

#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <errno.h>
#include <string.h>

#define FILENAME "/home/ftl/test_2_23"
#define SHMID 0x11223344
#define SIZE 4096

int GetKey()
{
    key_t n = ftok(FILENAME, SHMID);
    std::cout << n << std::endl;
    if (n == -1)
    {
        std::cerr << "error " << errno << " strerror: " << strerror(errno) << std::endl;
        exit(1);
    }
    return n;
}

int CreateShm(int key, int flag)
{
    int shmid = shmget(key, SIZE, flag);
    if (shmid < 0)
    {
        std::cerr << "error " << errno << " strerror: " << strerror(errno) << std::endl;
        exit(2);
    }
    return shmid;
}


int createshm(int key)
{
    return CreateShm(key, IPC_CREAT | IPC_EXCL | 0644);
}

int getshm(int key)
{
    return CreateShm(key, IPC_CREAT);
}